// 考勤列表

//公司
  $('.company_name').on('click',function(){
	opsearch('{:url("html/system/company")}?op=search')
})
// 添加司机考勤记录跳转
// $('#add').on('click',()=>{
//     window.location.href = "{:url('html/plus/accident_add')}"
// })
var page = 1;
var pagenum = 10;
var fi=1;
var between ='{$Think.get.between}';
var carID = '{$Think.get.car_id}';
var url={
    list:api.car.accidentlist,
    delete:api.car.accidentdelete,
}
var main=[[ //表头
    //  {type:'checkbox', fixed: 'left'},
    {field: 'driver_name', title: '司机', fixed: 'left'}
    ,{field: 'company_name', title: '所属公司',minWidth:170}
    ,{field: 'recent_totime', title: '最近出车时间',minWidth:170}
    ,{field:'recent_backtime', title:'最近归队时间',minWidth:170}
    ,{field:'ordernum', title:'工单数'}
    ,{field:'distance', title:'里程数'}
    ,{field:'hours', title:'任务时长'}
    ,{field:'star', title:'服务评价'}
    ,{field:'level', title:'业绩考评'}
    // ,{ title: '操作', toolbar:'#demo',fixed: 'right',align:'center'}
]];

var data={};
data.page=page;
data.pagenum=pagenum;
var where_json ={};
if(between){
    var start = '{$Think.get.between}'.split(' ');
	where_json.accident_time=['between time',[start[0],start[2]]]
}
   
if(carID){
    where_json.car_id=['in','{$Think.get.car_id}']
}
data.where_json=JSON.stringify(where_json)

ajaxattendance(data);
function ajaxattendance(data) {
    Load();
    //请求数据
    // ajax(url.list, data, 'post').done(function (res) {
        var  res ={            
            code : 1,
            count:16,
            list:[
            {driver_name:'小王1', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王2', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王3', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王4', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王5', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王6', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王7', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王8', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王9', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王10', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王11', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王12', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王13', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王14', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王15', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            {driver_name:'小王16', company_name:'小滴哥测试公司',recent_totime:"2018-08-06 15:33:55",recent_backtime:"2018-08-06 19:33:55",ordernum:110,distance:1220,hours:1250,star:5,level:'优'},        
            ]            
        }
        Load(1);
        // 成功回调
        //方法级表单渲染
        console.log(res)
        table.render({
            elem: '#driver_attendance',
            cols: main,
            data: res.list,
            limit: pagenum,
            cellMinWidth: 60
        });
        if(fi==1){
            laypage.render({
                elem: 'page'
                ,count: res.count
                ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,theme: '#1E9FFF'
                ,jump: function(obj, first){
                    console.log(obj)
                    if(obj.curr==2){
                        console.log(res.list)
                       var list= res.list.slice(9,16)
                        console.log(list)
                        table.render({
                            elem: '#driver_attendance',
                            cols: main,
                            data: list,
                            limit: pagenum,
                            cellMinWidth: 60
                        });
                    }else{
                        table.render({
                            elem: '#driver_attendance',
                            cols: main,
                            data: res.list,
                            limit: pagenum,
                            cellMinWidth: 60
                        });
                    }
                    if(!first){
                        page=obj.curr;
                        data.page=page;
                        pagenum=obj.limit;
                        data.pagenum=pagenum;
                        // ajaxattendance(data);
                    }else{
                        // console.log(first)
                    }
                }
              })
              fi = 2;
        }
        table.on('tool(demo)', function(obj){
            var data1 = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            // var data2 = {
            //     accident_ids:data1.accident_id
            // };
            
          if(layEvent==='detail'){
              console.log('订单列表详情')
              console.log(data1)
                // layer.confirm('是否删除', function (index) {
                //     Load()
                //     ajax(url.delete, data2, 'post').done(function (res) {
                //         // 成功回调
                //         console.log(res)
                //         layer.closeAll();
                //         Msg('删除成功');
                //         ajaxaccident(data)
                //     }).fail(function (err) {
                //         // 失败回调
                //         layer.close(deleteload);
                //         Err(res.msg ? res.msg : '操作失败，稍候再试');
                //     });
                //     layer.close(index);
                // })
            }
        })
           
    // }).fail(function (err) {
    //     // 失败回调
    //     Load(1)
    // 	Err('请求失败')
    // });

};